package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import com.manage.modules.dto.TBaseStationSelectDto;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseStationInfoVo;
import com.manage.modules.bo.TBaseStationInfoQueryBo;
import com.manage.modules.bo.TBaseStationInfoAddBo;
import com.manage.modules.bo.TBaseStationInfoEditBo;
import com.manage.modules.service.ITBaseStationInfoService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 站点信息Controller
 *
 * @author wx
 * @date 2021-08-11
 */
@Api(value = "站点信息控制器", tags = {"站点信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/info")
public class TBaseStationInfoController extends BaseController {

    private final ITBaseStationInfoService iTBaseStationInfoService;

    @GetMapping("/selectByDto")
    public AjaxResult selectByDto(TBaseStationSelectDto dto) {
        return AjaxResult.success(iTBaseStationInfoService.queryBySelectDto(dto));
    }

    /**
     * 查询站点信息列表
     */
    @ApiOperation("查询站点信息列表")
    @PreAuthorize("@ss.hasPermi('modules:info:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseStationInfoVo> list(TBaseStationInfoQueryBo bo) {
        startPage();
        List<TBaseStationInfoVo> list = iTBaseStationInfoService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出站点信息列表
     */
    @ApiOperation("导出站点信息列表")
    @PreAuthorize("@ss.hasPermi('modules:info:export')")
    @Log(title = "站点信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseStationInfoVo> export(TBaseStationInfoQueryBo bo) {
        List<TBaseStationInfoVo> list = iTBaseStationInfoService.queryList(bo);
        ExcelUtil<TBaseStationInfoVo> util = new ExcelUtil<TBaseStationInfoVo>(TBaseStationInfoVo.class);
        return util.exportExcel(list, "站点信息");
    }

    /**
     * 获取站点信息详细信息
     */
    @ApiOperation("获取站点信息详细信息")
    @PreAuthorize("@ss.hasPermi('modules:info:query')")
    @GetMapping("/{stationId}")
    public AjaxResult<TBaseStationInfoVo> getInfo(@PathVariable("stationId") Long stationId) {
        return AjaxResult.success(iTBaseStationInfoService.queryById(stationId));
    }

    /**
     * 新增站点信息
     */
    @ApiOperation("新增站点信息")
    @PreAuthorize("@ss.hasPermi('modules:info:add')")
    @Log(title = "站点信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseStationInfoAddBo bo) {
        return toAjax(iTBaseStationInfoService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改站点信息
     */
    @ApiOperation("修改站点信息")
    @PreAuthorize("@ss.hasPermi('modules:info:edit')")
    @Log(title = "站点信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseStationInfoEditBo bo) {
        return toAjax(iTBaseStationInfoService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除站点信息
     */
    @ApiOperation("删除站点信息")
    @PreAuthorize("@ss.hasPermi('modules:info:remove')")
    @Log(title = "站点信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{stationIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] stationIds) {
        return toAjax(iTBaseStationInfoService.deleteWithValidByIds(Arrays.asList(stationIds), true) ? 1 : 0);
    }
}
